﻿using CPF;
using CPF.Controls;
using CPF.Drawing;
using CPF.Input;
using CPF.Shapes;
using CPF.Styling;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace CPFUI
{
    public partial class BaseWindow : Window
    {
        public BaseWindow()
        {
            Width = 400; 
            Height = 400;
        }
        protected override void InitializeComponent()
        {
            IsAntiAlias = true;
#if DesignMode
            Width = 600;
            Height = 500;
            IconSize = 13;
#endif
            Background = null;
            //设置窗体阴影
            var frame = Children.Add(new Border
            {
                Size = SizeField.Fill,
                BorderType = BorderType.BorderStroke,
                BorderStroke = new Stroke(1),
                Bindings =
                {
                    {
                        nameof(Border.CornerRadius),
                        nameof(CornerRadius),
                        this,
                        BindingMode.OneWay
                    },
                    {
                        nameof(Border.BorderFill),
                        nameof(BorderColor),
                        this,
                        BindingMode.OneWay
                    },
                    {
                        nameof(Border.BorderStroke),
                        nameof(BorderWidth),
                        this,
                        BindingMode.OneWay,
                        (x)=>new Stroke((float)x)
                    },
                    {
                        nameof(Border.ShadowBlur),
                        nameof(WindowState),
                        this,
                        BindingMode.OneWay,
                        (x) => (WindowState)x == WindowState.Maximized ? 0 : ShadowBlur
                    },
                    {
                        nameof(Border.ShadowColor),
                        nameof(ShadowColor),
                        this,
                        BindingMode.OneWay
                    }
                }
            });
            frame.Child = new Grid
            {
                ClipToBounds = true,
                Size = SizeField.Fill,
                Bindings =
                {
                    {
                       nameof(Grid.CornerRadius),
                       nameof(CornerRadius),
                       this,
                       BindingMode.OneWay
                    },
                    {
                        nameof(Grid.Background),
                        nameof(FillBackground),
                        this,
                        BindingMode.OneWay
                    }
                },
                RowDefinitions =
                {
                    new RowDefinition()
                    {
                        Bindings =
                        {
                            {
                                nameof(RowDefinition.Height),
                                nameof(CaptionHeight),
                                this,
                                BindingMode.OneWay,
                                (x) => new GridLength((int)x, GridUnitType.Default)
                            }
                        }
                    },
                    new RowDefinition()
                    {
                        Height = GridLength.Star
                    }
                },
                Children =
                {
                    CaptionPanel,
                    ContentPanel
                }
            };
            CanResize = true;
        }
#if !DesignMode //用户代码写到这里，设计器下不执行，防止设计器出错
        protected override void OnInitialized()
        {
            base.OnInitialized();

        }
        //用户代码

#endif

    }
}
